package org.springblade.modules.sga.controller;

import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springblade.modules.sga.service.ISgaCityService;
import org.springblade.modules.sga.service.ISgaDictService;
import org.springblade.modules.sga.vo.SgaCityVO;
import org.springblade.modules.sga.vo.SgaDictVO;
import org.springblade.modules.system.service.IFileService;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping("/sga/admin")
public class SgaAdminController {
	private ISgaCityService cityService;
	private ISgaDictService dictService;
	private IFileService fileService;

	@GetMapping("/city/tree")
	public R<List<SgaCityVO>> cityTree() {
		// JSONArray data = JSON.parseArray("[{\"id\":1,\"parentId\":0,\"children\":[{\"id\":2,\"parentId\":1,\"children\":[{\"id\":3,\"parentId\":2,\"children\":[{\"id\":4,\"parentId\":3,\"children\":[],\"regionName\":\"襄城区\",\"regionLvl\":\"4\",\"regionCode\":\"420602\"},{\"id\":5,\"parentId\":3,\"children\":[],\"regionName\":\"樊城区\",\"regionLvl\":\"4\",\"regionCode\":\"420606\"},{\"id\":6,\"parentId\":3,\"children\":[],\"regionName\":\"襄州区\",\"regionLvl\":\"4\",\"regionCode\":\"420607\"},{\"id\":10,\"parentId\":3,\"children\":[],\"regionName\":\"南漳县\",\"regionLvl\":\"4\",\"regionCode\":\"420624\"},{\"id\":12,\"parentId\":3,\"children\":[],\"regionName\":\"谷城县\",\"regionLvl\":\"4\",\"regionCode\":\"420625\"},{\"id\":11,\"parentId\":3,\"children\":[],\"regionName\":\"保康县\",\"regionLvl\":\"4\",\"regionCode\":\"420626\"},{\"id\":9,\"parentId\":3,\"children\":[],\"regionName\":\"老河口市\",\"regionLvl\":\"4\",\"regionCode\":\"420682\"},{\"id\":7,\"parentId\":3,\"children\":[],\"regionName\":\"枣阳市\",\"regionLvl\":\"4\",\"regionCode\":\"420683\"},{\"id\":8,\"parentId\":3,\"children\":[],\"regionName\":\"宜城市\",\"regionLvl\":\"4\",\"regionCode\":\"420684\"},{\"id\":26,\"parentId\":3,\"children\":[],\"regionName\":\"高新区\",\"regionLvl\":\"4\",\"regionCode\":\"420662\"},{\"id\":27,\"parentId\":3,\"children\":[],\"regionName\":\"东津新区\",\"regionLvl\":\"4\",\"regionCode\":\"420661\"}],\"regionName\":\"襄阳市\",\"regionLvl\":\"3\",\"regionCode\":\"420600\"}],\"regionName\":\"湖北省\",\"regionLvl\":\"2\",\"regionCode\":\"420000\"}],\"regionName\":\"国家\",\"regionLvl\":\"0\",\"regionCode\":\"000000\"}]");
		List<SgaCityVO> data = cityService.cityTree();
		return R.data(data);
	}

	@GetMapping("/dict/getDictByType/{type}")
	public R<SgaDictVO> getDictByType(@PathVariable(name = "type") String type) {
//		Object data = null;
//		switch (type) {
//			case "HOT_TAG":
//				data = JSON.parse("{\"id\":363,\"type\":\"HOT_TAG\",\"description\":\"热门政策\",\"createTime\":\"2020-10-23 10:50:09\",\"updateTime\":\"2021-11-30 16:12:59\",\"system\":\"0\",\"remarks\":\"热门政策\",\"delFlag\":\"0\",\"tenantId\":1,\"dictItemList\":[{\"id\":2225,\"dictId\":2225,\"value\":\"税收减免\",\"label\":\"税收减免\",\"type\":\"HOT_TAG\",\"description\":\"税收减免\",\"sort\":0,\"createTime\":\"2020-11-04 15:51:56\",\"updateTime\":\"2022-04-12 12:26:12\",\"remarks\":\"\",\"delFlag\":\"0\",\"tenantId\":0,\"parentId\":0,\"children\":[]},{\"id\":2227,\"dictId\":363,\"value\":\"创业担保\",\"label\":\"创业担保\",\"type\":\"HOT_TAG\",\"description\":\"创业担保\",\"sort\":0,\"createTime\":\"2020-11-04 17:35:48\",\"updateTime\":\"2021-10-31 10:09:57\",\"remarks\":\"\",\"delFlag\":\"0\",\"tenantId\":0,\"parentId\":0,\"children\":[]},{\"id\":2233,\"dictId\":363,\"value\":\"奖励政策\",\"label\":\"奖励政策\",\"type\":\"HOT_TAG\",\"description\":\"奖励政策\",\"sort\":0,\"createTime\":\"2020-11-11 11:06:48\",\"updateTime\":\"2021-10-31 10:10:46\",\"remarks\":\"\",\"delFlag\":\"0\",\"tenantId\":0,\"parentId\":0,\"children\":[]}]}");
//				break;
//			case "HOT_TAG_MATTER":
//				data = JSON.parse("{\"id\":365,\"type\":\"HOT_TAG_MATTER\",\"description\":\"热词事项\",\"createTime\":\"2020-10-23 11:48:22\",\"updateTime\":\"2020-10-23 11:48:22\",\"system\":\"0\",\"remarks\":\"热词事项\",\"delFlag\":\"0\",\"tenantId\":1,\"dictItemList\":[{\"id\":2579,\"dictId\":2579,\"value\":\"企业技术中心\",\"label\":\"企业技术中心\",\"type\":\"HOT_TAG_MATTER\",\"description\":\"企业技术中心\",\"sort\":0,\"createTime\":\"2020-11-23 18:12:09\",\"updateTime\":\"2021-02-06 16:18:36\",\"delFlag\":\"0\",\"tenantId\":0,\"parentId\":0,\"children\":[]},{\"id\":2580,\"dictId\":2580,\"value\":\"小微企业融资\",\"label\":\"小微企业融资\",\"type\":\"HOT_TAG_MATTER\",\"description\":\"小微企业融资\",\"sort\":0,\"createTime\":\"2020-11-23 18:12:17\",\"updateTime\":\"2021-02-06 16:19:01\",\"delFlag\":\"0\",\"tenantId\":0,\"parentId\":0,\"children\":[]},{\"id\":2587,\"dictId\":2587,\"value\":\"“小升规”企业资金奖励\",\"label\":\"“小升规”企业资金奖励\",\"type\":\"HOT_TAG_MATTER\",\"description\":\"“小升规”企业资金奖励\",\"sort\":0,\"createTime\":\"2020-11-24 10:02:37\",\"updateTime\":\"2021-02-06 16:19:56\",\"delFlag\":\"0\",\"tenantId\":0,\"parentId\":0,\"children\":[]}]}");
//				break;
//		}
		SgaDictVO data = dictService.getDictByType(type);
		return R.data(data);
	}

	@GetMapping("/sys-file/minio/download")
	public void minioDownload(@RequestParam Long id, HttpServletResponse response) {
		fileService.downloadFileById(id, response);
	}
}
